package com.fight.strive.sys.modules.validator;

import com.fight.strive.sys.utils.ObjectUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;


@Aspect
@Component
public class StriveValidateAspect {

    @Around("execution(* *(.., @StriveValid (*), ..))")
    public Object handler(ProceedingJoinPoint pjp) throws Throwable {
        Object[] args = pjp.getArgs();
        if (ObjectUtils.notNull(args) && args.length > 0) {
            Object arg = args[0];
            StriveValidateUtils.validate(arg);
        }
        return pjp.proceed();
    }
}
